package cn.project.engineering.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import cn.project.engineering.R
import cn.project.engineering.base.MyAppCompatActivity
import cn.project.engineering.ui.adapter.ImagePagerAdapter
import cn.project.engineering.utils.IntentKey
import kotlinx.android.synthetic.main.activity_big_picture.*
import java.util.*

class BigPictureActivity : MyAppCompatActivity() {
    companion object{
        fun start(context: Context?, url: String) {
            val images = ArrayList<String>(1)
            images.add(url)
            start(context, images)
        }

        fun start(context: Context?, urls: ArrayList<String>?) {
           this.start(context, urls, 0)
        }
        fun start(context: Context?, urls: ArrayList<String>?, index: Int) {
            val intent = Intent(context, BigPictureActivity::class.java)
            intent.putExtra(IntentKey.IMAGE, urls)
            intent.putExtra(IntentKey.INDEX, index)
            context?.startActivity(intent)
        }
    }
    val handler = Handler(Looper.getMainLooper())
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_big_picture)
        initView();
        initData();
        handler.postDelayed(object :Runnable{
            override fun run() {
                finish()
            }
        },60000)
    }

    override fun netWork(isnet: Boolean) {
    }

    private fun initView() {
        pv_image_preview_indicator.setViewPager(vp_image_preview_pager)
    }


    private fun initData() {
        val images: ArrayList<String>? = intent.getStringArrayListExtra(IntentKey.IMAGE)
        val index: Int? = intent.getIntExtra(IntentKey.INDEX,0)


        if (images != null && images.size > 0) {
            vp_image_preview_pager.setAdapter(ImagePagerAdapter(this, images))
            if (index != 0 && index!! <= images.size) {
                vp_image_preview_pager.setCurrentItem(index)
            }
        } else {
            finish()
        }
    }


}

